package com.bd.scm.module.system.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bd.scm.domain.dto.overTime.OverTimeOrderFailDto;
import com.bd.scm.domain.models.system.BdSysCostcenter;
import com.bd.scm.module.common.BaseController;
import com.bd.scm.module.system.service.BdSysCostcenterService;
import com.bd.scm.module.utils.ResultUtil;
import com.bd.utils.IPUtil;
import com.bd.utils.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统设置-成本中心表 前端控制器
 * </p>
 *
 * @author Mason
 * @since 2020-08-14
 */
@Slf4j
@RestController
@RequestMapping("api/bdSysCostcenter")
public class BdSysCostcenterController extends BaseController {

    @Autowired
    private BdSysCostcenterService bdSysCostcenterService;

    /**
     * 获取成本中心.
     *
     * @param costcenterName
     * @return
     */
    @GetMapping("getCostcenterList")
    public Result getCostcenterList(String costcenterName) {
        log.info("getCostcenterList, 查询条件: {}", costcenterName);
        return ResultUtil.ok(bdSysCostcenterService.getCostcenterList(costcenterName));
    }

    /**
     * 新增或修改.
     *
     * @param bdSysCostcenter
     * @return
     */
    @PostMapping("addOrEdit")
    public Result addOrEdit(@RequestBody BdSysCostcenter bdSysCostcenter) {
        Result result = null;
        try {
            String msg = bdSysCostcenterService.addOrEdit(bdSysCostcenter);
            result = Result.ok("保存成功");
            if (null != msg) {
                result = Result.error(msg);
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = Result.error("服务器内部错误，保存失败");
        }
        return result;
    }

    /**
     * 删除.
     *
     * @param bdSysCostcenter
     * @return
     */
    @PostMapping("deleteCostCenter")
    public Result deleteCostCenter(@RequestBody BdSysCostcenter bdSysCostcenter) {
        Result result = null;
        try {
            String msg = bdSysCostcenterService.deleteCostCenter(bdSysCostcenter);
            result = Result.ok("删除成功");
            if (null != msg) {
                result = Result.error(msg);
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = Result.error("服务器内部错误，删除失败");
        }
        return result;
    }
}

